package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.constant.RedisConstant;
import com.sky.constant.StatusConstant;
import com.sky.context.BaseContext;
import com.sky.result.Result;
import com.sky.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.sky.constant.RedisConstant.KEY_STATUS;

/**
 * @Author : xiongke
 * @Description:
 * @Date: 2024/8/29
 */
@RestController("AdminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "管理端店铺相关接口")
@Slf4j
public class ShopController {

    @Resource
    RedisUtil redisUtil;

    @PutMapping("/{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("店铺营业状态设置为：{}",status == StatusConstant.ENABLE ? "营业中" : "已打烊");
        //营业状态写入redis
        redisUtil.set(KEY_STATUS,status.toString());
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("查询店铺营业状态")
    public Result getShopStatus(){
        log.info("查询当前店铺营业状态");
        String value = (String) redisUtil.get(KEY_STATUS);
        if (value == null){
            value = "0";
        }
        int result = Integer.parseInt(value);
        return Result.success(result);
    }
}
